﻿using MediatR;
using SystemLYH.API.Application.Command.ProcuredCommand;
using SystemLYH.Infrstructre.Impl;
using SystemLYH.Infrstructre.Interface;

namespace SystemLYH.API.Application.Handlers.ProcuredHandlers
{
	public class ProcuredDeleteHandlers : IRequestHandler<ProcuredDeleteCommand, int>
	{
		protected readonly IProcuredrequestRepository _procuredrequestRepository;
		/// <summary>
		/// 采购申请构造函数
		/// </summary>
		/// <param name="procuredrequestRepository"></param>
		public ProcuredDeleteHandlers(IProcuredrequestRepository procuredrequestRepository)
		{
			_procuredrequestRepository = procuredrequestRepository;
		}
		public async Task<int> Handle(ProcuredDeleteCommand request, CancellationToken cancellationToken)
		{
			var list = (await _procuredrequestRepository.GetAllAsync()).Where(x => request.ProcuredId.Contains(x.ProcuredId)).ToList();
			foreach (var item in list)
			{
				item.IsDelete = true;
				await _procuredrequestRepository.UpdateAsync(item);
			}
			return 1;
		}
	}
}
